#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define deb(a) cerr << #a << " = " << (a) << " ";
#define debn(a) cerr << #a << " = " << (a) << "\n";
#define debnl() cerr << "\n";

const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int INF = 1 << 30;
const ldb pi = fabsl(atan2(0.0, -1.0));
using namespace std;

const int MOD = 1000000007;
char s[1002], t[1002];
int dp[1010][1010][3][2];
pair <int, int> st[1000000];
int sz;
int n;
int T, k;

void Load()
{
	cin >> T >> k;
}

char *p;
int from;

int f(int i, int l, int less, int w)
{
	if (i == -1)
	{
		if (less != 2) return w;
		return 0;
    }
	if (dp[i][l][less][w] != -1) return dp[i][l][less][w];
	dp[i][l][less][w] = 0;
	if (less == 0) 
	{
		st[sz].first = i;
		st[sz++].second = l;
	}
	if (w) dp[i][l][less][w]++;
	int nless;
	int nw, nl;
	int j = from;
	from = 0;
	for (; j < 10; j++)
	{
		nless = less;
		nw = w;
		if (l == 0) nl = 0;
		else nl = (l + 1) % (k + 1);
		if (less == 0 && j < p[i] - '0') nless = 1;
		if (less == 0 && j > p[i] - '0') nless = 2;
		if ((j == 4 || j == 7) && l != 0) nw = 1;
		if (j == 4 || j == 7) nl = 1;
		dp[i][l][less][w] += f(i - 1, nl, nless, nw);
		dp[i][l][less][w] %= MOD;
	}
//	deb(i) deb(l) deb(less) deb(w) debn(dp[i][l][less][w]);
	return dp[i][l][less][w];
}

int get(char *s)
{
	n = strlen(s);
	reverse(s, s + n);
	for (int i = 0; i < sz; i++)
	{
		dp[st[i].first][st[i].second][0][0] = -1;
		dp[st[i].first][st[i].second][0][1] = -1;
	}
//	memset(dp, -1, sizeof(dp));
	sz = 0;
	p = s;
	from = 1;
	int r = f(n - 1, 0, 0, 0);
	reverse(s, s + n);
	return r;
}

int check(char *s)
{
	n = strlen(s);
	int lst = 0;
	for (int i = 0; i < n; i++)
	{
		if ((s[i] == '4' || s[i] == '7') && lst != 0) return 1;
		if ((s[i] == '4' || s[i] == '7')) lst = 1;
		else
		{
			if (lst != 0)
			 lst = (lst + 1) % (k + 1);
		}
	}
	return 0;
}


void Solve()
{
	int i;
	memset(dp, -1, sizeof dp);
	for (i = 0; i < T; i++)
	{
		scanf("%s%s", s, t);
//		cerr << get(s) << " " << get(t) << " " << s << " " << t  << " " << check(s) << "\n";
		int res = get(t);
		res -= get(s);
		res %= MOD;
		res += check(s);
		res %= MOD;
		res += MOD;
		res %= MOD;
		printf("%d\n", res);
	}
}

#define file "d"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	Load();
	Solve();
	return 0;
}
